package com.itheima.mapper;
import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {
//    //计算总条数
//    @Select("select count(*) from emp")
//    Long count();
//
//    //获取指定页码的数据
//    @Select("select id, username, password, name, gender, image, job, entrydate, create_time, update_time" +
//            " from emp " +
//            "limit #{startIndex},#{pageSize}")
//    List<Emp> list(Integer startIndex, Integer pageSize);

    //利用pageHelper获取指定页码的数据
//    @Select("select id, username, password, name, gender, image, job, entrydate, create_time, update_time from emp")
    List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);

    /**
     * 根据id批量删除员工数据
     * @param ids
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 添加员工
     * @param emp
     */
    @Insert("insert into emp(username,password,name,gender,image,job,entrydate,dept_id,create_time,update_time) " +
            "values (#{username},#{password},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    void addEmp(Emp emp);

    /**
     * 根据id查询员工数据
     * @param id
     * @return
     */
    @Select("select id, username, password, name, gender, image, job, entrydate, create_time, update_time from emp where id = #{id}")
    Emp queryEmpById(Integer id);

    /**
     * 修改员工信息
     * @param emp
     */
    void updateEmp(Emp emp);

    @Select("select id,username,password,name,gender,image,job,entrydate,dept_id,create_time,update_time from emp " +
            "where username=#{username} and password=#{password}")
    Emp login(Emp emp);
}